package com.likou;

public class q206 {

    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }


    public ListNode reverseList(ListNode head) {
        // 只有一个节点
        if (head == null) {
            return head;
        }

        ListNode p1 = null;
        ListNode p2 = head;

        while (p2 != null) {
            ListNode temp = p2.next;
            p2.next = p1;
            p1 = p2;
            p2 = temp;
        }

        return p1;
    }
}
